route.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as googleHandler } from "../../google";
  6. import { handle as anthropicHandler } from "../../anthropic";
  7. import { handle as baiduHandler } from "../../baidu";
  8. import { handle as bytedanceHandler } from "../../bytedance";
  9. import { handle as alibabaHandler } from "../../alibaba";
  10. import { handle as moonshotHandler } from "../../moonshot";
  11. import { handle as stabilityHandler } from "../../stability";
  12. import { handle as iflytekHandler } from "../../iflytek";
  13. import { handle as deepseekHandler } from "../../deepseek";
  14. import { handle as siliconflowHandler } from "../../siliconflow";
  15. import { handle as xaiHandler } from "../../xai";
  16. import { handle as chatglmHandler } from "../../glm";
  17. import { handle as proxyHandler } from "../../proxy";
  18. async function handle(
  19. req: NextRequest,
  20. { params }: { params: { provider: string; path: string[] } },
  21. ) {
  22. const apiPath = `/api/${params.provider}`;
  23. console.log(`[${params.provider} Route] params `, params);
  24. switch (apiPath) {
  25. case ApiPath.Azure:
  26. return azureHandler(req, { params });
  27. case ApiPath.Google:
  28. return googleHandler(req, { params });
  29. case ApiPath.Anthropic:
  30. return anthropicHandler(req, { params });
  31. case ApiPath.Baidu:
  32. return baiduHandler(req, { params });
  33. case ApiPath.ByteDance:
  34. return bytedanceHandler(req, { params });
  35. case ApiPath.Alibaba:
  36. return alibabaHandler(req, { params });
  37. // case ApiPath.Tencent: using "/api/tencent"
  38. case ApiPath.Moonshot:
  39. return moonshotHandler(req, { params });
  40. case ApiPath.Stability:
  41. return stabilityHandler(req, { params });
  42. case ApiPath.Iflytek:
  43. return iflytekHandler(req, { params });
  44. case ApiPath.DeepSeek:
  45. return deepseekHandler(req, { params });
  46. case ApiPath.XAI:
  47. return xaiHandler(req, { params });
  48. case ApiPath.ChatGLM:
  49. return chatglmHandler(req, { params });
  50. case ApiPath.SiliconFlow:
  51. return siliconflowHandler(req, { params });
  52. case ApiPath.OpenAI:
  53. return openaiHandler(req, { params });
  54. default:
  55. return proxyHandler(req, { params });
  56. }
  57. }
  58. export const GET = handle;
  59. export const POST = handle;
  60. export const runtime = "edge";
  61. export const preferredRegion = [
  62. "arn1",
  63. "bom1",
  64. "cdg1",
  65. "cle1",
  66. "cpt1",
  67. "dub1",
  68. "fra1",
  69. "gru1",
  70. "hnd1",
  71. "iad1",
  72. "icn1",
  73. "kix1",
  74. "lhr1",
  75. "pdx1",
  76. "sfo1",
  77. "sin1",
  78. "syd1",
  79. ];